/**
 * 获取当前的时间
 * @returns {string} 时分秒
 */
export const getCurrentDate = () => {
    let date = new Date();
    let h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
    let m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
    return `${h}:${m}:${s}`
}
/**
 * 随机生成六位整数
 */
export const RandomlyNum = () => {
    return parseInt(((Math.random() * 1000000 - 100000) + 100000).toString())
}
/**
 * 将base64转换为Blob
 * @param dataurl base64
 * @returns 
 */
export const Base64toBlob = (dataurl: any) => {
    let arr = dataurl.split(','),
        mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]),
        n = bstr.length,
        u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], {
        type: mime
    });
}

/**
 * 添加弹出框提示信息
 * @param text 文本信息
 * @param duration 时间间隔
 */
export const MaskPopup = (text: string, duration?: number) => {
    let mask = document.getElementsByClassName("MaskMessage");
    let len = mask.length;
    for (let i = 0; i < len; i++) {
        let rect = mask[i].getBoundingClientRect();
        let height = i * 70;
        (mask[i] as HTMLElement).style.cssText = `left:${rect.left}px;top:${height}px;`
    }
    let ps = document.createElement("div");
    ps.innerHTML = text;
    ps.classList.add("MaskMessage")
    let w = (text.length * 18) / 2;
    let h = (len - 1) * 70;
    ps.style.cssText = `left:calc(50% - ${w}px);top:calc(10% + ${h}px);`;
    document.body.appendChild(ps)
    setTimeout(() => {
        document.body.removeChild(ps)
    }, duration || 2000)
}